package org.dromara.nursing.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.nursing.domain.vo.StaffSkillVo;
import org.dromara.nursing.domain.bo.StaffSkillBo;
import org.dromara.nursing.service.IStaffSkillService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 员工专业技能
 *
 * @author Xue
 * @date 2025-04-01
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/nursing/staffSkill")
public class StaffSkillController extends BaseController {

    private final IStaffSkillService staffSkillService;

    /**
     * 查询员工专业技能列表
     */
    @SaCheckPermission("nursing:staffSkill:list")
    @GetMapping("/list")
    public TableDataInfo<StaffSkillVo> list(StaffSkillBo bo, PageQuery pageQuery) {
        return staffSkillService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出员工专业技能列表
     */
    @SaCheckPermission("nursing:staffSkill:export")
    @Log(title = "员工专业技能", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(StaffSkillBo bo, HttpServletResponse response) {
        List<StaffSkillVo> list = staffSkillService.queryList(bo);
        ExcelUtil.exportExcel(list, "员工专业技能", StaffSkillVo.class, response);
    }

    /**
     * 获取员工专业技能详细信息
     *
     * @param skillId 主键
     */
    @SaCheckPermission("nursing:staffSkill:query")
    @GetMapping("/{skillId}")
    public R<StaffSkillVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long skillId) {
        return R.ok(staffSkillService.queryById(skillId));
    }

    /**
     * 新增员工专业技能
     */
    @SaCheckPermission("nursing:staffSkill:add")
    @Log(title = "员工专业技能", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody StaffSkillBo bo) {
        return toAjax(staffSkillService.insertByBo(bo));
    }

    /**
     * 修改员工专业技能
     */
    @SaCheckPermission("nursing:staffSkill:edit")
    @Log(title = "员工专业技能", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody StaffSkillBo bo) {
        return toAjax(staffSkillService.updateByBo(bo));
    }

    /**
     * 删除员工专业技能
     *
     * @param skillIds 主键串
     */
    @SaCheckPermission("nursing:staffSkill:remove")
    @Log(title = "员工专业技能", businessType = BusinessType.DELETE)
    @DeleteMapping("/{skillIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] skillIds) {
        return toAjax(staffSkillService.deleteWithValidByIds(List.of(skillIds), true));
    }
}
